﻿using HamcoWcs.Models.Common;
using System;
using System.Security.Cryptography;
using System.Text;

namespace HamcoWcs.Models.ForeEndModels.UIPaths
{
    public class UIPathUpdateModel : BaseModel
    {
        //public string PathName { get; set; }
        //public string FromNode { get; set; }
        //public string ToNode { get; set; }
        public int PathType { get; set; }
        public string DefaultPath { get; set; }
        public string AlternatePaths { get; set; }
    }


    public class UIPathQueryModel : PageSize
    {
        public string PathName { get; set; }
        public string FromNode { get; set; }
        public string ToNode { get; set; }
    }


    public class UIPathInfo
    {
        public string PathName { get; set; }

        public string FromNode { get; set; }

        public string ToNode { get; set; }

        //public string PathValue { get; set; }

        public int PathType { get; set; }

        public string DefaultPath { get; set; }
        public string AlternatePaths { get; set; } = "";

        public bool Enabled { get; set; } = true;
    }

    public class UIAddPathModel
    {
        public string  From { get; set; }
        public string To { get; set; }
        public string DefaultPath { get; set; }
    }

    public class UIAddEdgeModel
    {
        public string From { get; set; }
        public string To { get; set; }

        
    }


    public class UIPathGenerateToken
    {
        public string Token { get; set; }

        public void Update()
        {
            var k = DateTime.Now.Ticks.ToString();
            using (var md5 = MD5.Create())
            {
                var pwds = md5.ComputeHash(Encoding.UTF8.GetBytes(k));
                var pwd = new StringBuilder();
                foreach (var item in pwds)
                {
                    pwd.Append(item.ToString("X2"));
                }
                Token = pwd.ToString().ToUpper();
            }
        }

        public bool Compared(string token)
        {
            if (token.ToUpper() == this.Token)
            {
                this.Token = "";
                return true;
            }
            return false;
        }
    }
}
